package com.friend.street.util;


import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class CalendarUtil {
	/**
	 * 带日期的格式
	 */
	public static final String DATE_PATTERN = "yyyy-MM-dd";
	/**
	 * 带日期和时间的格式
	 */
	public static final String DATE_TIME_PATTERN = "yyyy-MM-dd HH:mm:ss";
	/**
	 * 不带秒的日期时间格式
	 */
	public static final String DATE_HOUR_MINUTE_PATTERN = "yyyy-MM-dd HH:mm";
	/**
	 * 不带秒数的时间
	 */
	public static final String TIME_PATTERN_WITHOUT_SECOND = "HH:mm";
	public static Calendar convertStringToDate(String dateStr){
		return convertStringToDate(dateStr,DATE_TIME_PATTERN);
	}
	/**
	 * 将字符串格式转成时间格式
	 * @param dateStr
	 * @param pattern
	 * @return
	 */
	public static Calendar convertStringToDate(String dateStr,String pattern){
		Calendar c = Calendar.getInstance();
		try{
			DateFormat format = new SimpleDateFormat(pattern);
			Date date = format.parse(dateStr);
			c.clear();
			c.setTime(date);
		}catch(Exception e){
			e.printStackTrace();
		}
		return c;
	}
	/**
	 * 将时间转成字符串格式
	 * @param c
	 * @param pattern
	 * @return
	 */
	public static String convertDateToString(Calendar c,String pattern){
		DateFormat format = new SimpleDateFormat(pattern);
		return format.format(c.getTime());
	}
	/**
	 * 得到中文的星期几
	 * @param c
	 * @return
	 */
	public static String getWeek(Calendar c){
		int dayOfWeek = c.get(Calendar.DAY_OF_WEEK);
		String week = "";
		switch(dayOfWeek){
			case  1 : {
				week = "星期天";
				break;
			}
			case 2 : {
				week = "星期一";
				break;
			}
			case 3 : {
				week = "星期二";
				break;
			}
			case 4 : {
				week = "星期三";
				break;
			}
			case 5 : {
				week = "星期四";
				break;
			}
			case 6 : {
				week = "星期五";
				break;
			}
			case 7 : {
				week = "星期六";
				break;
			}
		}
		return week;
	}
	public static void main(String args[]){
		//System.out.println(convertDateToString(Calendar.getInstance(),TIME_PATTERN_WITHOUT_SECOND));
		Calendar now = Calendar.getInstance();
		System.out.println(now.get(Calendar.DAY_OF_WEEK));
		now.set(2012, 3, 23);
		System.out.println(now.getTime());
		System.out.println(now.get(Calendar.DAY_OF_WEEK_IN_MONTH));
		
	}
	

}
